<template>
	<view class="page bg-fff col-3e">
		<view class="topBg bg-theme"></view>
		<view class="content">
			<user-card-default></user-card-default>
			
			<menus></menus>
			
			<cell-list-default :sellerStatus="adviserStatus" :check="pushChecked"></cell-list-default>
		</view>

        <up-gap height="40" />

		<tabbar></tabbar>
	</view>
</template>

<script setup>
	import UserCardDefault from './components/user-card-default.vue';
	import menus from './components/menus.vue';
	import CellListDefault from './components/cell-list-default.vue';
	import { ref } from 'vue';
	import { onShow } from '@dcloudio/uni-app';
	import { storeToRefs } from 'pinia';
	import { useUserInfoStore, useIndexStore } from '@/store/index';
	// import { checkLogin, checkWXPrivacyAuthorize, savePhotoAuth, checkUserInfo } from '@/common/common';
	import { getQrcode, readMsgAPI, pushHouseMsg } from '@/common/api';
	import { openAgreement, openPolicy } from '@/common/utils/docts';
    // import { adviserHome } from '@/common/api-adviser';
    // import { getImgInfo } from '@/common/canvas-tools';

	const userInfoStore = useUserInfoStore();
	const indexStore = useIndexStore();

	const { userInfo } = storeToRefs(userInfoStore);

	let adviserStatus = ref(3);//0:审核中  1:审核成功 2:审核失败 3:从未申请
	let pushChecked = ref(false);

	onShow(async () => {
		await init();
	});

	//初始化
	async function init(){
		// await requestAdviserStatus();
		await userInfoStore.checkUserInfo();//验证用户信息,如果没有就获取并且更新
		await getPushStatus();
	}

	//请求顾问审核状态
	// async function requestAdviserStatus(){
	// 	try{
	// 		const {status, detail} = await adviserExamine();
	// 		if(status !== 0) {
	// 			uni.$u.toast(detail);
	// 			return;
	// 		}
	// 		adviserStatus.value = detail.check;
	// 		//置业顾问状态  0:审核中  1:审核成功 2:审核失败 3:从未申请
	// 		if(detail.check == 1 && userInfo.value.is_login) {
	// 			indexStore.setAdviserId(detail.sid);
	// 			indexStore.setIsAdviser(true);
	// 			await reqAdviserData();

	// 			uni.setNavigationBarTitle({
	// 				title: '顾问之家'
	// 			});
	// 		}else {
	// 			indexStore.setIsAdviser(false);
	// 			uni.setNavigationBarTitle({
	// 				title: '个人中心'
	// 			});
	// 		}
	// 	}catch(e){
	// 		console.log(e);
	// 	}
	// }

	//置业顾问接口
	async function reqAdviserData(){
		try {
			// const { status, detail } = await adviserHome(indexStore.adviserId);
			// if(status !== 0) {
			// 	uni.$u.toast(detail);
			// 	return;
			// }
			// let { points_v2, product, seller, qr_url, new_points_index } = detail;
			// this.adviserInfo = seller;
			// this.integralNum = points_v2;
			// this.product = product;
			// this.qrcode = qr_url;
			// this.kaiId = product.pan_id;
			// this.rankIndex = new_points_index;
			// if(!this.userInfo) {
			// 	getUserInfo().then(res => {
			// 		if(res.status == 0){
			// 			this.setUserInfo(res.detail);
			// 			uni.setStorage({
			// 				key: 'userInfo',
			// 				data: res.detail
			// 			})
			// 		}
			// 	})
			// }
		} catch (error) {
			console.log(error)
		}
    }

	//获取推送状态
	async function getPushStatus(){
		try{
			const {status, detail} = await pushHouseMsg('get');
			if(status !== 0) {
				uni.$u.toast(detail);
				return;
			}
			pushChecked.value = detail;
		}catch(error){
			console.log(error)
		}
	}
</script>

<style lang="scss" scoped>
.page{
	min-height: 100vh;
	overflow: hidden;
	position: relative;
	.topBg{
		height: 363rpx;
	}
	.content{
		margin-top: -300rpx;
		padding: 0rpx 30rpx;
	}
}
</style>